// 实现 创建虚拟DOM对象

// 虚拟 DOM 对象 构造函数
function Element(type,props,children) {

    this.type = type;
    this.props = props;
    this.children = children;
}

// 创建 虚拟DOM对象
function createElement(type,props,children) {

    return new Element(type,props,children);
}

// 将虚拟 DOM 转换为真实DOM
function render(vdomObj) {
    let {type,props,children} = vdomObj;

    // 构造dom节点
    let ele = document.createElement(type);

    // 给dom节点添加属性
    for(let key in props){
        
        ele.setAttribute(key,props[key]);
        
    };
     

    // 遍历孩子节点，将孩子节点转换成dom节点
    children.forEach( child => {
        
        console.log(child instanceof Element);

        child = (child instanceof Element)?render(child):document.createTextNode(child);

        ele.appendChild(child);
    });

    return ele;
}






export {

    Element,
    createElement,
    render
}